package com.ruoyi.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AssetStockDetail;
import com.ruoyi.asset.service.IAssetStockDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点记录Controller
 * 
 * @author asset
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/asset/stockDetail")
public class AssetStockDetailController extends BaseController
{
    @Autowired
    private IAssetStockDetailService assetStockDetailService;

    /**
     * 查询盘点记录列表
     */
    @PreAuthorize("@ss.hasPermi('asset:stockDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetStockDetail assetStockDetail)
    {
        startPage();
        List<AssetStockDetail> list = assetStockDetailService.selectAssetStockDetailList(assetStockDetail);
        return getDataTable(list);
    }

    /**
     * 导出盘点记录列表
     */
    @PreAuthorize("@ss.hasPermi('asset:stockDetail:export')")
    @Log(title = "盘点记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetStockDetail assetStockDetail)
    {
        List<AssetStockDetail> list = assetStockDetailService.selectAssetStockDetailList(assetStockDetail);
        ExcelUtil<AssetStockDetail> util = new ExcelUtil<AssetStockDetail>(AssetStockDetail.class);
        util.exportExcel(response, list, "盘点记录数据");
    }

    /**
     * 获取盘点记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetStockDetailService.selectAssetStockDetailById(id));
    }

    /**
     * 获取设备最新的盘点记录详细信息
     */
    @GetMapping(value = "/asset/{assetId}")
    public AjaxResult stockInfo(@PathVariable("assetId") Long assetId)
    {
        return success(assetStockDetailService.selectAssetStockDetailByAssetId(assetId));
    }

    /**
     * 新增盘点记录
     */
    @PreAuthorize("@ss.hasPermi('asset:stockDetail:add')")
    @Log(title = "盘点记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetStockDetail assetStockDetail)
    {
        return toAjax(assetStockDetailService.insertAssetStockDetail(assetStockDetail));
    }

    /**
     * 修改盘点记录
     */
    @Log(title = "盘点记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetStockDetail assetStockDetail)
    {
        return toAjax(assetStockDetailService.updateAssetStockDetail(assetStockDetail));
    }

    /**
     * 删除盘点记录
     */
    @PreAuthorize("@ss.hasPermi('asset:stockDetail:remove')")
    @Log(title = "盘点记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetStockDetailService.deleteAssetStockDetailByIds(ids));
    }
}
